package com.gxa.meiye.portal.service.impl;


import com.gxa.meiye.core.pojo.domain.Order;
import com.gxa.meiye.core.utils.RestUtils;

import com.gxa.meiye.portal.service.ShopOrderService;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Map;

@Service
public class ShopOrderServiceImpl implements ShopOrderService {
    @Resource(name = "myJmsTemplate")
    private JmsMessagingTemplate jmsMessagingTemplate=null;

    @Override
    public boolean orderCoupon(String phone, Order order) {
        order.setPhone(phone);
        order.setTime(LocalDateTime.now());
        jmsMessagingTemplate.convertAndSend("orderCoupon",order);
        return true;
    }

    @Override
    public boolean orderAdd(String phone,Order order) {
        //Map<String,Object> map=new HashMap();
        order.setPhone(phone);

        //order.
        jmsMessagingTemplate.convertAndSend("orderCha",order);
        return true;
    }
    //支付成功
    @Override
    public boolean update(String orderNumber,String serialNumber) {
        String url="http://1.117.60.194:8080/order/updateZF";
        MultiValueMap<String,Object> params=new LinkedMultiValueMap<>();
        params.add("orderNumber",orderNumber);
        params.add("serialNumber",serialNumber);
        Map map = RestUtils.postWithParams(url, params);
        if (map.get("code").equals("1")){
            return true;
        }
        return false;
    }
}
